package com.live.stamp.web.oss.controller;

import com.live.stamp.base.token.TokenAuth;
import com.live.stamp.web.oss.service.OssService;
import org.springframework.boot.container.core.common.BusinessException;
import org.springframework.boot.container.core.common.ServerResponse;
import org.springframework.boot.container.core.controller.BaseRestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author cwd E-mail: wendong.cao@jsxfedu.com
 * @version 1
 * @date 2018/4/18 15:16
 */
@RestController
@RequestMapping("/oss")
public class OssController extends BaseRestController {

    @Resource
    OssService ossService;

    /**
     * @api {post} /oss/getOssStsToken 获取oss STS token
     * @apiSampleRequest /oss/getOssStsToken
     * @apiName getOssStsToken
     * @apiGroup oss
     * @apiDescription 获取oss STS token
     * @apiParamExample {json} 参数示例:
     * {
     *
     * }
     * @apiSuccessExample {json} 返回示例:
     * HTTP/1.1 200 OK
     {
        "StatusCode": "200",
        "AccessKeyId": "STS.CT74vkthPobVsVA8oWsCgjwY5",
        "AccessKeySecret": "3S8sDg4cWhr3BNGREMTa4QmcqYCyd788EAecju5cNfMC",
        "SecurityToken": "CAIShgJ1q6Ft5B2yfSjIopeCf8zfmbdx2KC9cXDw3G8Cf8xLhbLy1zz2IHBOe3VvCeAbtvswmWhU5/gclqVoRoReREvCKM1565kPZ8dXtU+F6aKP9rUhpMCPOwr6UmzWvqL7Z+H+U6muGJOEYEzFkSle2KbzcS7YMXWuLZyOj+wMDL1VJH7aCwBLH9BLPABvhdYHPH/KT5aXPwXtn3DbATgD2GM+qxsmsvjimpfHsEWO0AOqk7REnemrfMj4NfsLFYxkTtK40NZxcqf8yyNK43BIjvwm1vMYpmeX44nCXAQJv0TYbfCn+9luPRJ/YbMhB6lHof7zmPt1oOXPkJ7tzBJALSKl0tkdxVnKGoABsMSLJ6NmC3eZCTAWi8Xa5X3Yd+ckvDxv3sBnNGY32J1yiLiRodYWDy4Oigq641o+crJiXXfZtn6EAfO5mvIfuq0/5LawNEmsVBVFPJKyB8CZA0ZVO/E44a+VWkSiCmF3jtQ2gfdLmAa11QfXMyDxS0nbfZImI/EY/Jfg4rEkBDQ=",
        "Expiration": "2018-04-18T08:03:24Z"
        }
     */
//    @TokenAuth
    @RequestMapping("/getOssStsToken")
    public Map<String, Object> getOssStsToken() {
//        ServerResponse serverResponse = new ServerResponse();
//        try{
//            serverResponse.setCode(200);
//            serverResponse.setData(ossService.getStsToken());
//        }catch (BusinessException e) {
//            serverResponse.setCode(ServerResponse.ERROR_BBUSINESS);
//            serverResponse.setMsg(e.getMessage());
//        }
//        return serverResponse;

        return ossService.getStsToken();
    }
}
